home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00a.txt / 000021_icon-group-sender _Wed Feb 2 12:26:35 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA04465
  4.     for icon-group-addresses; Wed, 2 Feb 2000 12:25:00 -0700 (MST)
  5. Message-Id: <200002021925.MAA04465@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 02 Feb 2000 10:50:20 -0600
  7. From: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  8. To: <icon-group@optima.CS.Arizona.EDU>
  9. Subject: Icon parameter values
  10. Content-Disposition: inline
  11. X-Guinevere: 1.0.12 ; Oceaneering Int'l
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id KAA00040
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. Thanks to all who sent in their comments on my "mini-dissertation" of a few days ago.  I am all straightened out on this now.
  17.  
  18. Shamim Mohamed said it this way in referring to my "beast in captivity" program snippet:
  19.  
  20. >In method 1, you are creating a new list and assigning a reference to it
  21. >to the name x.
  22. >In method 2, you are modifying the list that x has a reference to.
  23.  
  24. This difference between x := [value] and put(x, value) accounts for my confusion as to why I sometimes could, and sometimes couldn't, update the array.  In short, I was doing it both ways at different times without fully comprehending the difference.  There is no low-level clue to the different behavior in the syntax; one just has to have read the fine print.  RTFM, I think they say.
  25.  
  26. In reading what I could find about the parameter problem in the 2nd Ed. of Ralph's book (yes, I know--I need to get the 3rd), I could find nothing in the vein of "If you want to update a structured parameter from within a procedure, here is how to do it: ..."
  27.  
  28. So, in the interest of filling the gap for newcomers and oldtimers alike who may be confused, here is how to do it and guarantee that the update will make it back to the caller:
  29.  
  30. # append a value to list_arg, which is passed in from the caller
  31. procedure append_it(list_arg)
  32.     local new_list_value
  33.     new_list_value := # result of some computation
  34.     put(list_arg, new_list_value)
  35.     return
  36. end
  37.  
  38. # change an element of list_arg:
  39. procedure change_it(list_arg)
  40.     local changed_list_value, i
  41.     i := # e.g. a binary search for the proper element to modify
  42.     changed_list_value := # result of some computation
  43.     list_arg[i] := changed_list_value
  44.     return
  45. end
  46.  
  47. And here is how NOT to do it:
  48.  
  49. # Grrr...
  50. procedure how_dumb(list_arg)
  51.     local new_list
  52.     list_arg := [ # sequence of new values computed locally from list_arg
  53.         ]
  54.     return
  55. end
  56.  
  57. If anybody sees problems with these examples, be sure to chime in.
  58.  
  59. Charles Hethcoat
  60.  
  61.